TARGET = ledblink
PORTA = COM4
MEGA = 168
PROGRAMADOR = avrispv2

CC = avr-gcc
CFLAGS = -Wall -Os -mcall-prologues -mmcu=atmega$(MEGA)
OBJ2HEX = avr-objcopy
AVRDUDE = avrdude
DUDEFLAGS = -c $(PROGRAMADOR) -p m$(MEGA) -P $(PORTA) -e -U lfuse:w:0xe6:m

upload: $(TARGET).hex
	$(AVRDUDE) $(DUDEFLAGS) -U flash:w:$<

%.hex: %.obj
	$(OBJ2HEX) -R .eeprom -O ihex $< $@

%.obj: %.o
	$(CC) $(CFLAGS) $< -o $@

%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<

clean:
	rm -f *.hex *.obj *.o *~ \#*\#

all: upload
